﻿#Region "Copyright"
'————————————————————————————————————————
'	创建人员(Creator)    ：Huangyd
'	创建日期(Date)       ：2012-07-14
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'	Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region
Imports System.Drawing

Namespace Drawing

    Public Class GraphicsHelper

        ''' <summary>
        ''' 根据给定的区域得到中心的正方形区域
        ''' </summary>
        ''' <param name="rect"></param>
        ''' <returns></returns>
        Public Shared Function GetCenterRectangle(ByVal rect As Rectangle) As Rectangle
            Dim _SquareRect As Rectangle = Rectangle.Empty

            If rect.Width <= rect.Height Then
                With _SquareRect
                    .X = rect.Left
                    .Y = CInt((rect.Height - rect.Width) / 2) + rect.Top
                    .Width = rect.Width
                    .Height = rect.Width
                End With
            Else
                With _SquareRect
                    .X = CInt((rect.Width - rect.Height) / 2) + rect.Left
                    .Y = rect.Top
                    .Width = rect.Height
                    .Height = rect.Height
                End With
            End If

            Return _SquareRect
        End Function

        ''' <summary>
        ''' 绘制对角的交叉线
        ''' </summary>
        ''' <param name="g"></param>
        ''' <param name="rect"></param>
        ''' <remarks></remarks>
        Public Shared Sub DrawCrossLine(ByVal g As Graphics, ByVal rect As Rectangle, ByVal pen As Pen)
            DrawCrossLine(g, rect, pen, 5)
        End Sub
        ''' <summary>
        ''' 绘制对角的交叉线
        ''' </summary>
        ''' <param name="g"></param>
        ''' <param name="rect"></param>
        ''' <remarks></remarks>
        Public Shared Sub DrawCrossLine(ByVal g As Graphics, ByVal rect As Rectangle, ByVal pen As Pen, ByVal space As Integer)
            Dim _SquareRect As Rectangle = GetCenterRectangle(rect)
            _SquareRect.Inflate(-space, -space)

            g.DrawLine(pen, _SquareRect.Left, _SquareRect.Top, _SquareRect.Right, _SquareRect.Bottom)
            g.DrawLine(pen, _SquareRect.Left, _SquareRect.Bottom, _SquareRect.Right, _SquareRect.Top)
        End Sub

        ''' <summary>
        ''' 绘制水平、垂直的交叉线
        ''' </summary>
        ''' <param name="g"></param>
        ''' <param name="rect"></param>
        ''' <remarks></remarks>
        Public Shared Sub DrawHorCrossLine(ByVal g As Graphics, ByVal rect As Rectangle)
            Throw New NotImplementedException()
        End Sub




    End Class
End Namespace

